package com.heima.behavior.listener;

import com.alibaba.fastjson.JSON;
import com.heima.behavior.dto.FollowBehaviorDto;
import com.heima.behavior.service.IApFollowBehaviorService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.concurrent.ConcurrentHashMap;

@Service
public class FollowListener {
    @Autowired
    private IApFollowBehaviorService apFollowBehaviorService;
@KafkaListener(topics = "${topic.followBehaviorTopic}")
    public void handleMessage(ConsumerRecord<String, String> record) {
    String value = record.value();
    if (!StringUtils.isEmpty(value)) {
        //将消息装换为dto对象
        FollowBehaviorDto behaviorDto = JSON.parseObject(value, FollowBehaviorDto.class);
        //进行保存
        apFollowBehaviorService.saveFollow(behaviorDto);
    }

}
}
